package com.iot.ic.common.job;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.iot.ic.common.utils.ResourceUtil;
import org.quartz.SchedulerException;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

public class QuartzContextListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {

	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		SchedulerFactoryBean schedule = ResourceUtil
				.getBean(SchedulerFactoryBean.class);
		if (schedule != null) {
			try {
				schedule.destroy();
			} catch (SchedulerException e) {
				e.printStackTrace();
			}
		}

		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
